<template>
	<div class="forgetview allbgc">
		<div class="logview-top logreg-top alltop">
			<span>
				<router-link to="/log"><</router-link>
			</span>
			<p>
				<span>
					请重置密码
				</span>
			</p>
		</div>

		<div class="forgetview-main">
			<div class="forgetview-from logreg-from">
				<label><input type="text" placeholder="填写手机号" v-model="username" /></label>
				<label><input type="password" placeholder="请输入新设置的密码" v-model="password" /></label>
				<label><input type="password" placeholder="请输入验证码" v-model="vercode" /><button>发送验证码</button></label>
			</div>
			<div class="photo">
				<button><router-link to="/log">去登录</router-link></button>
			</div>
		</div>
	</div>
</template>

<script>
	import {
		Toast
	} from 'mint-ui';

	export default {
		data() {
			return {
				username: '',
				password: '',
				vercode: ''
			}
		},
		methods: {
			reg() {
				//先做判断   后调用接口发送数据
				console.log(this.username)
				if (this.username == "") {
					Toast({
						message: '手机号不能为空',
						position: 'top',
						duration: 1500
					});
					//return false上面执行以后下面代码不在执行
					return false
				}
				if (this.password == "") {
					Toast({
						message: '密码不能为空',
						position: 'top',
						duration: 1500
					});
					return false
				}
				if (this.vercode == "") {
					Toast({
						message: '请输入验证码',
						position: 'top',
						duration: 1500
					});
					return false
				}
				// post(接口地址,要发送的数据是什么)
				//qs.stringify可以使发送的数据有序化
				this.$http.post("/user/forget", this.qs.stringify({
					username: this.username,
					password: this.password,
					vercode: this.vercode,
				})).then(res => {
					//.then 成功
					console.log(res)
					Toast({
						message: '密码已重置',
						position: 'top',
						duration: 1500
					});
					//跳转到log页面
					this.$router.push('log')
				}).catch(err => {
					//.catch 失败
					//response 响应
					//status 状态码
					console.log(err)
					console.log(err.response.status)
					if (err.response.status == 409) {
						Toast({
							message: '用户名未注册',
							position: 'top',
							duration: 1500
						});
					}
					if (err.response.status == 401) {
						Toast({
							message: '网络异常,请稍后重试',
							position: 'top',
							duration: 1500
						});
					}
				})
			}
		}
	}
</script>

<style>
	.forgetview-from label button{
		top: 113px;
	}
	.forgetview-main a{
		color: #fff;
	}
</style>
